import request from '@/utils/request';

// 用户登录
export function login(data) {
  return request({
    url: '/api/user/login',
    method: 'post',
    data
  });
}

// 用户注册
export function register(data) {
  return request({
    url: '/api/user/register',
    method: 'post',
    data
  });
}

// 获取用户信息
export function getUserInfo() {
  return request({
    url: '/api/user/info',
    method: 'get'
  });
}

// 更新用户信息
export function updateUserInfo(data) {
  return request({
    url: '/api/user/update',
    method: 'put',
    data
  });
}

// 修改密码
export function changePassword(oldPassword, newPassword, confirmPassword) {
  return request({
    url: '/api/user/password',
    method: 'put',
    params: {
      oldPassword,
      newPassword,
      confirmPassword
    }
  });
}

// 用户登出
export function logout() {
  return request({
    url: '/api/user/logout',
    method: 'post'
  });
}

// 发送验证码
export function sendVerificationCode(phone) {
  return request({
    url: `/api/user/send-code?phone=${phone}`,
    method: 'get'
  });
}

// 上传头像
export function uploadAvatar(file) {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/api/upload/avatar',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

// 更新头像
export function updateAvatar(avatarUrl) {
  return request({
    url: '/api/user/avatar',
    method: 'put',
    params: {
      avatarUrl
    }
  });
}
